/**
 * Created by gengrong on 16/4/11.
 */
import { actionTypeCreatorWithNameSpace, createAction } from './util';
import agent from 'agent';

const actionTypeCreator = actionTypeCreatorWithNameSpace('devTeam');

var environmentId = null;

export const setEnvironmentId = (id)=> {
  environmentId = id;
}

export const getEnvironmentId = ()=> {
  return environmentId
}

export const fetchEnvironmentList = createAction(actionTypeCreator('environmentList'), () => {
  return agent.get(`/api/v1/environments`)
    .then(response => response.body);
});

export const createEnvironment = createAction(actionTypeCreator('environmentById'), (environment) => {
  return agent.post(`/api/v1/environments`)
    .send(environment)
    .then(response => response.body);
});

export const removeEnvironment = createAction(actionTypeCreator('environmentById'), (environmentId) => {
  return agent.del(`/api/v1/environments/${environmentId}`)
    .then(response => response.body);
});

export const updateEnvironment = createAction(actionTypeCreator('serviceById'), (environment) => {
  return agent.put(`/api/v1/environments/${environment.id}`)
    .send(environment)
    .then(response => response.body);
});
